package com.qd.common.panda.domain.entity.space;

import com.cdqidi.util.DateUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * 承租信息
 *
 * @author sjk
 */
@Getter
@Setter
public class ParkInfoSpaceTenantDTO {

    /**
     * 主键
     */
    private String id;
    /**
     * 租赁开始时间
     */
    private String startDate;
    /**
     * 租赁结束时间
     */
    private String endDate;
    /**
     * 车主总收益
     */
    @JsonIgnore
    private BigDecimal deductionTotalRevenue;
    /**
     * 车主总收益显示
     */
    private String deductionTotalRevenueDisplay;
    /**
     * 租赁人车牌号
     */
    private String tenantNumber;
    /**
     * 下单时间
     */
    private LocalDateTime orderTime;
    /**
     * 是否当天订单
     */
    private Boolean currentDay;
    /**
     * 0表示进行中，1表示已结束
     */
    private Integer state;

    public Boolean getCurrentDay() {
        LocalDate start = DateUtil.strToLocalDate(startDate);
        LocalDate end = DateUtil.strToLocalDate(endDate);
        LocalDate now = LocalDate.now();
        return (now.isAfter(start) || now.equals(start)) && (now.isBefore(end) || now.equals(end));
    }

    public String getDeductionTotalRevenueDisplay() {
        return Optional.ofNullable(deductionTotalRevenue).orElse(new BigDecimal("0")).stripTrailingZeros().toPlainString();
    }

    public void freeData() {
        this.id = null;
        this.startDate = null;
        this.endDate = null;
        this.deductionTotalRevenue = null;
        this.deductionTotalRevenueDisplay = null;
        this.orderTime = null;
        this.tenantNumber = null;
        this.currentDay = null;
        this.state = null;
    }
}
